package com.agritech.service.impl;

import com.agritech.entity.Category;
import com.agritech.mapper.CategoryMapper;
import com.agritech.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 分类服务实现类
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    
    @Autowired
    private CategoryMapper categoryMapper;
    
    @Override
    public List<Category> getAllCategories() {
        return categoryMapper.selectAll();
    }
    
    @Override
    public Category getCategoryById(Long id) {
        return categoryMapper.selectById(id);
    }
    
    @Override
    public boolean addCategory(Category category) {
        int result = categoryMapper.insert(category);
        return result > 0;
    }
    
    @Override
    public boolean updateCategory(Category category) {
        int result = categoryMapper.update(category);
        return result > 0;
    }
    
    @Override
    public boolean deleteCategory(Long id) {
        int result = categoryMapper.delete(id);
        return result > 0;
    }
}    